package com.sxyjhh.fg_data_push;

import com.sxyjhh.fg_data_push.dao.CreditPersonNormBadRepository;
import com.sxyjhh.fg_data_push.dao.PersonTypeRepository;
import com.sxyjhh.fg_data_push.dao.SecurityProcityareaRepository;
import com.sxyjhh.fg_data_push.po.CreditPersonNormBad;
import com.sxyjhh.fg_data_push.po.PersonType;
import com.sxyjhh.fg_data_push.po.SecurityProcityarea;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;

import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class InitDataFactory implements CommandLineRunner {

    @Autowired
    private SecurityProcityareaRepository securityProcityareaRepository;
    @Autowired
    private CreditPersonNormBadRepository creditPersonNormBadRepository;
    @Autowired
    private PersonTypeRepository personTypeRepository;

    private Map<String, Map<String, String>> dicMap = null;

    private void initSysDicData() {

        long count = securityProcityareaRepository.count();
        long num = 1000;
        long batch = ((count / num) + (count % num != 0 ? 1 : 0));

        Map<String, String> qhDicMap = new HashMap<>();
        for (int i = 0; i < batch; i++) {

            Pageable pageable = new PageRequest(i, 1000);
            Page<SecurityProcityarea> page = securityProcityareaRepository.findAll(pageable);
            List<SecurityProcityarea> list = page.getContent();
            list.forEach(sp ->  qhDicMap.put(sp.getId(),sp.getName()));

        }

        Map<String,String> rylxDicMap = new HashMap<>();
        Iterable<PersonType> it = personTypeRepository.findAll();
        for(PersonType type : it){
            rylxDicMap.put(type.getName(),type.getValue());
        }

        dicMap = new HashMap<>();

        Map<String, String> wfbmDicMap = new HashMap<>();

        Iterable<CreditPersonNormBad>  creditPersonNormBads = creditPersonNormBadRepository.findAll();

        creditPersonNormBads.forEach(creditPersonNormBad -> {
            wfbmDicMap.put(creditPersonNormBad.getActivecode(),creditPersonNormBad.getBadactive());
        });

        Map<String, String> fsdxzDicMap = new HashMap<>();
        fsdxzDicMap.put("1","省");
        fsdxzDicMap.put("2","市");
        fsdxzDicMap.put("3","区");
        fsdxzDicMap.put("4","省直管区");

        Map<String, String> cfbmDicMap = new HashMap<>();
        cfbmDicMap.put("0","部级");
        cfbmDicMap.put("1","地方");

        Map<String, String> blflDicMap = new HashMap<>();
        blflDicMap.put("1","行政处罚");
        blflDicMap.put("2","行政处理");
        blflDicMap.put("3","通报");
        blflDicMap.put("5","其他");

        Map<String, String> xwDicMap = new HashMap<>();
        xwDicMap.put("0","良好行为");
        xwDicMap.put("1","不良行为");

        Map<String, String> zjlxDicMap = new HashMap<>();
        zjlxDicMap.put("1","身份证");
        zjlxDicMap.put("2","军官证");
        zjlxDicMap.put("3","护照");
        zjlxDicMap.put("4","台湾居民身份证");
        zjlxDicMap.put("5","香港永久性居民身份证");
        zjlxDicMap.put("6","警官证");

        Map<String, String> bmjbDicMap = new HashMap<>();
        bmjbDicMap.put("0","部级");
        bmjbDicMap.put("1","地方");

        Map<String, String> hylbDicMap = new HashMap<>();

        //130 房地产开发
        hylbDicMap.put("130","7010");
        //186 房地产估价  /
        hylbDicMap.put("186","7090");
        //187 物业
        hylbDicMap.put("187","7020");
        //175 检测机构
        hylbDicMap.put("175","7451");
        //125 工程监理
        hylbDicMap.put("125","7482");
        //202 规划编制
        hylbDicMap.put("202","7485");
        //185 造价咨询
        hylbDicMap.put("185","7249");


        //国民经济类型
        Map<String, String> jjlxDicMap = new HashMap<>();

        //130
        jjlxDicMap.put("110003016","290");
        jjlxDicMap.put("110003043","230");
        jjlxDicMap.put("110003013","151");
        jjlxDicMap.put("110003009","130");
        jjlxDicMap.put("110003041","160");
        jjlxDicMap.put("110003086","900");
        jjlxDicMap.put("110003034","330");
        jjlxDicMap.put("110003080","310");
        jjlxDicMap.put("110003036","320");
        jjlxDicMap.put("110003008","230");
        jjlxDicMap.put("110003033","330");
        jjlxDicMap.put("110003031","330");
        jjlxDicMap.put("110003017","230");
        jjlxDicMap.put("110003088","900");
        jjlxDicMap.put("110003015","110");
        jjlxDicMap.put("110003004","130");
        jjlxDicMap.put("110003096","159");
        jjlxDicMap.put("110003021","159");
        jjlxDicMap.put("110003040","173");
        jjlxDicMap.put("110003003","120");
        jjlxDicMap.put("110003085","171");
        jjlxDicMap.put("110003012","171");
        jjlxDicMap.put("110003081","110");
        jjlxDicMap.put("110003030","330");
        jjlxDicMap.put("110003027","159");
        jjlxDicMap.put("110003010","130");
        jjlxDicMap.put("110003028","290");
        jjlxDicMap.put("110003090","310");
        jjlxDicMap.put("110003082","159");
        jjlxDicMap.put("110003087","160");
        jjlxDicMap.put("110003011","174");
        jjlxDicMap.put("110003039","310");
        jjlxDicMap.put("110003006","160");
        jjlxDicMap.put("110003018","120");
        jjlxDicMap.put("110003020","160");
        jjlxDicMap.put("110003089","159");
        jjlxDicMap.put("110003023","160");
        jjlxDicMap.put("110003092","160");
        jjlxDicMap.put("110003042","149");
        jjlxDicMap.put("110003029","220");
        jjlxDicMap.put("110003002","110");
        jjlxDicMap.put("110003025","160");
        jjlxDicMap.put("110003026","330");
        jjlxDicMap.put("110003037","159");
        jjlxDicMap.put("110003000","159");
        jjlxDicMap.put("110003022","160");
        jjlxDicMap.put("110003019","120");
        jjlxDicMap.put("110003035","310");
        jjlxDicMap.put("110003094","160");
        jjlxDicMap.put("110003083","330");
        jjlxDicMap.put("110003044","160");
        jjlxDicMap.put("110003084","230");
        jjlxDicMap.put("110003007","230");
        jjlxDicMap.put("110003059","174");
        jjlxDicMap.put("110003095","160");
        jjlxDicMap.put("110003024","210");
        jjlxDicMap.put("110003038","310");
        jjlxDicMap.put("110003014","171");
        jjlxDicMap.put("110003093","160");
        jjlxDicMap.put("110003032","330");
        jjlxDicMap.put("110003091","171");
        //186
        jjlxDicMap.put("11002335","159");
        jjlxDicMap.put("110023005","149");
        jjlxDicMap.put("11002336","900");
        jjlxDicMap.put("11002331","230");
        jjlxDicMap.put("11002332","230");
        jjlxDicMap.put("11002319","290");
        jjlxDicMap.put("11002329","171");
        jjlxDicMap.put("11002325","310");
        jjlxDicMap.put("11002330","174");
        jjlxDicMap.put("11002324","330");
        jjlxDicMap.put("11002313","151");
        jjlxDicMap.put("110023009","330");
        jjlxDicMap.put("11002312","159");
        jjlxDicMap.put("11002321","330");
        jjlxDicMap.put("11002316","290");
        jjlxDicMap.put("11002318","210");
        jjlxDicMap.put("11002327","320");
        jjlxDicMap.put("110023010","900");
        jjlxDicMap.put("11002320","330");
        jjlxDicMap.put("110023006","160");
        jjlxDicMap.put("110023003","120");
        jjlxDicMap.put("11002314","159");
        jjlxDicMap.put("11002328","171");
        jjlxDicMap.put("11002315","230");
        jjlxDicMap.put("110023004","130");
        jjlxDicMap.put("11002322","330");
        jjlxDicMap.put("11002334","330");
        jjlxDicMap.put("110023002","110");
        jjlxDicMap.put("11002333","160");
        jjlxDicMap.put("11002311","900");
        jjlxDicMap.put("110023007","174");
        jjlxDicMap.put("11002326","310");
        jjlxDicMap.put("11002323","330");
        jjlxDicMap.put("110023001","159");
        jjlxDicMap.put("11002317","210");
        jjlxDicMap.put("110023008","290");
        //187
        jjlxDicMap.put("110016022","173");
        jjlxDicMap.put("110016050","310");
        jjlxDicMap.put("110016021","310");
        jjlxDicMap.put("110016049","159");
        jjlxDicMap.put("110016062","174");
        jjlxDicMap.put("110016029","174");
        jjlxDicMap.put("110016034","171");
        jjlxDicMap.put("110016020","320");
        jjlxDicMap.put("110016027","310");
        jjlxDicMap.put("110016019","310");
        jjlxDicMap.put("110016018","330");
        jjlxDicMap.put("110016017","330");
        jjlxDicMap.put("110016032","330");
        jjlxDicMap.put("110016016","330");
        jjlxDicMap.put("110016015","330");
        jjlxDicMap.put("110016014","330");
        jjlxDicMap.put("110016013","220");
        jjlxDicMap.put("110016033","210");
        jjlxDicMap.put("110016012","290");
        jjlxDicMap.put("110016024","230");
        jjlxDicMap.put("110016011","159");
        jjlxDicMap.put("110016023","151");
        jjlxDicMap.put("110016061","159");
        jjlxDicMap.put("110016030","159");
        jjlxDicMap.put("110016001","159");
        jjlxDicMap.put("110016035","171");
        jjlxDicMap.put("110016026","171");
        jjlxDicMap.put("110016025","171");
        jjlxDicMap.put("110016054","159");
        jjlxDicMap.put("110016009","330");
        jjlxDicMap.put("110016053","330");
        jjlxDicMap.put("110016055","230");
        jjlxDicMap.put("110016007","174");
        jjlxDicMap.put("110016048","160");
        jjlxDicMap.put("110016056","900");
        jjlxDicMap.put("110016057","900");
        jjlxDicMap.put("110016046","159");
        jjlxDicMap.put("110016010","900");
        jjlxDicMap.put("110016028","160");
        jjlxDicMap.put("110016045","160");
        jjlxDicMap.put("110016005","149");
        jjlxDicMap.put("110016044","120");
        jjlxDicMap.put("110016003","120");
        jjlxDicMap.put("110016043","120");
        jjlxDicMap.put("110016051","310");
        jjlxDicMap.put("110016042","290");
        jjlxDicMap.put("110016002","110");
        jjlxDicMap.put("110016041","110");
        jjlxDicMap.put("110016052","110");
        jjlxDicMap.put("110016058","160");
        jjlxDicMap.put("110016006","160");
        jjlxDicMap.put("110016060","160");
        jjlxDicMap.put("110016031","160");
        jjlxDicMap.put("110016059","160");
        jjlxDicMap.put("110016036","160");
        jjlxDicMap.put("110016040","130");
        jjlxDicMap.put("110016039","130");
        jjlxDicMap.put("110016004","130");
        jjlxDicMap.put("110016008","290");
        jjlxDicMap.put("110016047","160");
        jjlxDicMap.put("110016038","230");
        jjlxDicMap.put("110016037","230");

        //101
        jjlxDicMap.put("110000002","110");
        jjlxDicMap.put("110000003","120");
        jjlxDicMap.put("1100000125","120");
        jjlxDicMap.put("1100000140","120");
        jjlxDicMap.put("110000004","130");
        jjlxDicMap.put("1100000138","130");
        jjlxDicMap.put("110000005","149");
        jjlxDicMap.put("110000112","151");
        jjlxDicMap.put("1100000129","159");
        jjlxDicMap.put("110000010","159");
        jjlxDicMap.put("110000118","159");
        jjlxDicMap.put("1100000135","159");
        jjlxDicMap.put("110000000","159");
        jjlxDicMap.put("110000131","160");
        jjlxDicMap.put("110000115","160");
        jjlxDicMap.put("1100000123","160");
        jjlxDicMap.put("1100000124","160");
        jjlxDicMap.put("1100000139","160");
        jjlxDicMap.put("1100000126","160");
        jjlxDicMap.put("1100000136","160");
        jjlxDicMap.put("110000006","160");
        jjlxDicMap.put("110000121","171");
        jjlxDicMap.put("110000119","171");
        jjlxDicMap.put("1100000122","171");
        jjlxDicMap.put("110000117","171");
        jjlxDicMap.put("1100000134","173");
        jjlxDicMap.put("110000113","174");
        jjlxDicMap.put("1100000132","174");
        jjlxDicMap.put("110000007","174");
        jjlxDicMap.put("110000114","210");
        jjlxDicMap.put("1110000190","230");
        jjlxDicMap.put("110000111","230");
        jjlxDicMap.put("110000008","290");
        jjlxDicMap.put("1100000133","310");
        jjlxDicMap.put("1100000127","310");
        jjlxDicMap.put("1100000128","310");
        jjlxDicMap.put("110000009","330");
        jjlxDicMap.put("1100000141","330");
        jjlxDicMap.put("1100000130","330");
        jjlxDicMap.put("1100000131","330");

        //185
        jjlxDicMap.put("110012115","173");
        jjlxDicMap.put("110012136","174");
        jjlxDicMap.put("110012134","174");
        jjlxDicMap.put("110012126","171");
        jjlxDicMap.put("110012142","310");
        jjlxDicMap.put("110012132","310");
        jjlxDicMap.put("110012139","330");
        jjlxDicMap.put("110012137","330");
        jjlxDicMap.put("110012129","230");
        jjlxDicMap.put("110012121","210");
        jjlxDicMap.put("110012127","230");
        jjlxDicMap.put("110012112","159");
        jjlxDicMap.put("110012143","151");
        jjlxDicMap.put("110012135","159");
        jjlxDicMap.put("110012130","159");
        jjlxDicMap.put("110012000","159");
        jjlxDicMap.put("110012140","171");
        jjlxDicMap.put("110012138","171");
        jjlxDicMap.put("110012113","171");
        jjlxDicMap.put("110012124","310");
        jjlxDicMap.put("110012009","330");
        jjlxDicMap.put("110012007","174");
        jjlxDicMap.put("110012122","900");
        jjlxDicMap.put("110012111","159");
        jjlxDicMap.put("110012110","900");
        jjlxDicMap.put("110012116","160");
        jjlxDicMap.put("110012128","160");
        jjlxDicMap.put("110012123","900");
        jjlxDicMap.put("110012118","900");
        jjlxDicMap.put("110012005","149");
        jjlxDicMap.put("110012114","120");
        jjlxDicMap.put("110012003","120");
        jjlxDicMap.put("110012002","110");
        jjlxDicMap.put("110012125","130");
        jjlxDicMap.put("110012133","160");
        jjlxDicMap.put("110012131","160");
        jjlxDicMap.put("110012119","160");
        jjlxDicMap.put("110012117","160");
        jjlxDicMap.put("110012006","160");
        jjlxDicMap.put("110012141","130");
        jjlxDicMap.put("110012004","130");
        jjlxDicMap.put("110012008","290");

        //125
        jjlxDicMap.put("1100010018","173");
        jjlxDicMap.put("110001000","159");
        jjlxDicMap.put("110001113","174");
        jjlxDicMap.put("110001111","174");
        jjlxDicMap.put("1100010030","171");
        jjlxDicMap.put("1100010024","310");
        jjlxDicMap.put("1100010023","310");
        jjlxDicMap.put("1100010020","330");
        jjlxDicMap.put("1100010021","330");
        jjlxDicMap.put("1100010039","230");
        jjlxDicMap.put("1100010036","210");
        jjlxDicMap.put("1100010038","230");
        jjlxDicMap.put("1100010022","159");
        jjlxDicMap.put("1100010037","151");
        jjlxDicMap.put("110001112","159");
        jjlxDicMap.put("1100010033","159");
        jjlxDicMap.put("1100010042","159");
        jjlxDicMap.put("1100010032","171");
        jjlxDicMap.put("1100010035","171");
        jjlxDicMap.put("1100010031","171");
        jjlxDicMap.put("1100010019","310");
        jjlxDicMap.put("110001009","330");
        jjlxDicMap.put("110001007","174");
        jjlxDicMap.put("110001114","900");
        jjlxDicMap.put("110001110","159");
        jjlxDicMap.put("110001115","900");
        jjlxDicMap.put("1100010028","160");
        jjlxDicMap.put("1100010029","160");
        jjlxDicMap.put("1100010016","900");
        jjlxDicMap.put("110001005","149");
        jjlxDicMap.put("1100010026","120");
        jjlxDicMap.put("110001003","120");
        jjlxDicMap.put("110001002","110");
        jjlxDicMap.put("110001006","160");
        jjlxDicMap.put("1100010017","160");
        jjlxDicMap.put("1100010025","160");
        jjlxDicMap.put("1100010027","160");
        jjlxDicMap.put("1100010034","160");
        jjlxDicMap.put("1100010041","160");
        jjlxDicMap.put("110001004","130");
        jjlxDicMap.put("110001008","290");

        //175
        jjlxDicMap.put("110010002","110");
        jjlxDicMap.put("110010003","120");
        jjlxDicMap.put("110010004","130");
        jjlxDicMap.put("110010009","330");
        jjlxDicMap.put("110010006","160");
        jjlxDicMap.put("110010013","174");
        jjlxDicMap.put("110010012","159");
        jjlxDicMap.put("110010008","290");
        jjlxDicMap.put("110010015","900");
        jjlxDicMap.put("110010011","900");
        jjlxDicMap.put("110010110","900");
        jjlxDicMap.put("110010014","159");
        jjlxDicMap.put("110010007","174");
        jjlxDicMap.put("110010000","159");
        jjlxDicMap.put("110010005","149");

        //202
        jjlxDicMap.put("110024004","130");
        jjlxDicMap.put("110024002","110");
        jjlxDicMap.put("110024006","160");
        jjlxDicMap.put("110024010","900");
        jjlxDicMap.put("110024007","174");
        jjlxDicMap.put("110024009","330");
        jjlxDicMap.put("110024000","159");
        jjlxDicMap.put("110024008","290");
        jjlxDicMap.put("110024005","149");
        jjlxDicMap.put("110024003","120");


        //勘察设计
        jjlxDicMap.put("18040","320");
        jjlxDicMap.put("18038","310");
        jjlxDicMap.put("18080","174");
        jjlxDicMap.put("18056","174");
        jjlxDicMap.put("18066","171");
        jjlxDicMap.put("18074","310");
        jjlxDicMap.put("18076","330");
        jjlxDicMap.put("18072","159");
        jjlxDicMap.put("18060","159");
        jjlxDicMap.put("18078","159");
        jjlxDicMap.put("18058","159");
        jjlxDicMap.put("18015","159");
        jjlxDicMap.put("18042","330");
        jjlxDicMap.put("18044","340");
        jjlxDicMap.put("18024","173");
        jjlxDicMap.put("18022","172");
        jjlxDicMap.put("18026","174");
        jjlxDicMap.put("18020","171");
        jjlxDicMap.put("18054","900");
        jjlxDicMap.put("18016","159");
        jjlxDicMap.put("18052","390");
        jjlxDicMap.put("18028","900");
        jjlxDicMap.put("18012","149");
        jjlxDicMap.put("18064","160");
        jjlxDicMap.put("18050","290");
        jjlxDicMap.put("18062","900");
        jjlxDicMap.put("18002","120");
        jjlxDicMap.put("18008","142");
        jjlxDicMap.put("18032","220");
        jjlxDicMap.put("18030","210");
        jjlxDicMap.put("18010","143");
        jjlxDicMap.put("18000","110");
        jjlxDicMap.put("18006","141");
        jjlxDicMap.put("18068","900");
        jjlxDicMap.put("18014","110");
        jjlxDicMap.put("18070","160");
        jjlxDicMap.put("18018","160");
        jjlxDicMap.put("18004","130");
        jjlxDicMap.put("18046","175");
        jjlxDicMap.put("18048","900");
        jjlxDicMap.put("18036","240");
        jjlxDicMap.put("18034","230");
        //
        Map<String, String> jzlxDicMap = new HashMap<>();

        jzlxDicMap.put("环保工程105002","4862");
        jzlxDicMap.put("建筑工程105001","4710");
        jzlxDicMap.put("公路工程105001","4812");
        jzlxDicMap.put("铁路工程105001","4811");
        jzlxDicMap.put("水利水电工程105001","4820");
        jzlxDicMap.put("电力工程105001","4579");
        jzlxDicMap.put("市政公用工程105001","4813");
        jzlxDicMap.put("桥梁工程105002","4819");
        jzlxDicMap.put("隧道工程105002","4819");
        jzlxDicMap.put("建筑装修装饰工程105002","5012");
        jzlxDicMap.put("建筑机电安装工程105002","4920");
        jzlxDicMap.put("建筑幕墙工程105002","5013");
        jzlxDicMap.put("港口与海岸工程105002","4823");
        jzlxDicMap.put("水利水电机电安装工程105002","4820");
        jzlxDicMap.put("河湖整治工程105002","4822");


        dicMap.put("qhDic",qhDicMap);
        dicMap.put("rylxDic",rylxDicMap);
        dicMap.put("fsdxzDic",fsdxzDicMap);
        dicMap.put("cfbmDic",cfbmDicMap);
        dicMap.put("blflDic",blflDicMap);
        dicMap.put("xwDic",xwDicMap);
        dicMap.put("wfbmDic",wfbmDicMap);
        dicMap.put("zjlxDic",zjlxDicMap);
        dicMap.put("hylbDic",hylbDicMap);
        dicMap.put("jjlxDic",jjlxDicMap);
        dicMap.put("jzlxDic",jzlxDicMap);
    }

    @Override
    public void run(String... strings) throws Exception {
        System.out.println("加载字典数据");
        initSysDicData();
        System.out.println("加载字典数据完成");
    }

    public Map<String, Map<String, String>> getDicMap() {
        return dicMap;
    }

}
